/**
 * @file implements DataCookieWriter
 * @author CORSAIR <vladimir.corsair@gmail.com>
 * @version 1.2a
 * @interface for DataWriter
 */

/**
 * Write local data with cookies
 * @returns {DataCookieWriter}
 */
var DataCookieWriter = function () {
    this.set = function(key, value, days) {
        var date, expires;
        if (days) {
            date = new Date();
            date.setTime(date.getTime() + (days ? days : 1 * 24 * 60 * 60 * 1000));
            expires = "; expires=" + date.toGMTString();
        } else {
            expires = "";
        }
        document.cookie = key + "=" + value + expires + "; path=/";
    };
    
    this.get = function (key) {
        var i, c, ca, nameEQ = key + "=";
        ca = document.cookie.split(';');
        for (i = 0; i < ca.length; i++) {
            c = ca[i];
            while (c.charAt(0) === ' ') {
                c = c.substring(1, c.length);
            }
            if (c.indexOf(nameEQ) === 0) {
                return c.substring(nameEQ.length, c.length);
            }
        }
    };
    
    this.remove = function (key) {
        var data = document.cookie.split("; ");
        for(var x in data) {
            var keyData = data[x].split("=");
            if(keyData[0] === key) {
                this.set(key, "", -1);
                break;
            }
        }
    };
};